package com.hmkj.core.api.ufx.mc;

import com.hundsun.mcapi.MCServers;
import com.hundsun.mcapi.exception.MCSubscribeException;
import com.hundsun.mcapi.interfaces.ISubscriber;
import com.hundsun.mcapi.subscribe.MCSubscribeParameter;


public class UFXMC {
    /**
     * 国际期货行情主推订阅
     */
    public void reqFunctionSubQuoOut() {
        //获取MC服务中订阅接口
        try {
            ISubscriber subscriber = MCServers.GetSubscriber();
            MCSubscribeParameter subParam = new MCSubscribeParameter();
            byte[] data = {1, 3, 5, 8, 9, 10, 2, 3, 0};
            subParam.SetAppData(data);//添加附加数据
            subParam.SetTopicName("ofutu.quotation_push");
            subParam.SetFromNow(false);
            subTopic(subscriber, subParam, 3000);
        } catch (MCSubscribeException e) {
            e.printStackTrace();
        }
    }

    /**
     * 国内期货行情主推订阅
     */
    public void reqFunctionSubQuoIn() {
        //获取MC服务中订阅接口
        try {
            ISubscriber subscriber = MCServers.GetSubscriber();
            MCSubscribeParameter subParam = new MCSubscribeParameter();
            byte[] data = {1, 3, 5, 8, 9, 10, 2, 3, 0};
            subParam.SetAppData(data);//添加附加数据
            subParam.SetTopicName("futu.quotation_push");
            subParam.SetFromNow(false);
            subTopic(subscriber, subParam, 3000);
        } catch (MCSubscribeException e) {
            e.printStackTrace();
        }
    }

    /**
     * 国际期货交易主推订阅（委托回报  成交回报）
     */
    public void reqFunctionTradeOut(String accountNo) {
        //获取MC服务中订阅接口
        try {
            ISubscriber subscriber = MCServers.GetSubscriber();
            MCSubscribeParameter subParam = new MCSubscribeParameter();
            byte[] data = {1, 3, 5, 8, 9, 10, 2, 3, 0};
            subParam.SetAppData(data);//添加附加数据
            subParam.SetFilter("fund_account", accountNo);
            subParam.SetTopicName("ovfutu.trade_push");
            subParam.SetFromNow(false);
            subTopic(subscriber, subParam, 3000);
        } catch (MCSubscribeException e) {
            e.printStackTrace();
        }
    }

    /**
     * 国内期货交易主推订阅（委托回报  成交回报）
     */
    public void reqFunctionTradeIn(String accountNo) {
        //获取MC服务中订阅接口
        try {
            ISubscriber subscriber = MCServers.GetSubscriber();
            MCSubscribeParameter subParam = new MCSubscribeParameter();
            byte[] data = {1, 3, 5, 8, 9, 10, 2, 3, 0};
            subParam.SetAppData(data);//添加附加数据
            subParam.SetFilter("fund_account", accountNo);
            subParam.SetTopicName("futu.trade_push");
            subParam.SetFromNow(false);
            subTopic(subscriber, subParam, 3000);
        } catch (MCSubscribeException e) {
            e.printStackTrace();
        }
    }


    private void subTopic(ISubscriber subscriber, MCSubscribeParameter subParam, int paramInt) throws MCSubscribeException {
        int iRet = subscriber.SubscribeTopic(subParam, 3000);
        if (iRet > 0) {
            System.out.println("订阅成功");
        } else {
            System.out.println("订阅失败:" + MCServers.GetErrorMsg(iRet));
        }
    }


}
